<template>
	<div>

		<el-tabs v-model="activeName" :stretch="flag" type="border-card" @tab-click="handleClick">
			<el-tab-pane label="短期订单" name="first">
				<div Style="margin: 0 auto; width: 70%; height: 750px;">
					<shortOrderInfo :shortOrderList="shortOrderList"></shortOrderInfo>
				</div>
			</el-tab-pane>
			<el-tab-pane label="长期订单" name="second">
				<div Style="margin: 0 auto; width: 70%; height: 750px;">
					<longOrderInfo :longOrderList="longOrderList"></longOrderInfo>
				</div>
			</el-tab-pane>
			<el-tab-pane label="专业订单" name="third">
				<div Style="margin: 0 auto; width: 70%; height: 750px;">
					<majorOrderInfo :majorOrderList="majorOrderList"></majorOrderInfo>
				</div>
			</el-tab-pane>
			<el-tab-pane label="信息总览" name="five">
				<div Style="margin: 0 auto; width: 80%; height: 750px;">
					<orderBrowse :assessList="assessList" :Lengths="Lengths"></orderBrowse>
				</div>
			</el-tab-pane>
		</el-tabs>
	</div>
</template>

<script>
	// import mealInfo from '@/components/meal_info/Meal_info.vue'
	import orderBrowse from '@/components/order_browse/order_browse.vue'
	import shortOrderInfo from '@/components/short_order_info/short_order_info.vue'
	import longOrderInfo from '@/components/long_order_info/long_order_info.vue'
	import majorOrderInfo from '@/components/major_order_info/major_order_info.vue'
	import {
		request
	} from "network/request.js"
	export default {
		name: 'Order_main',
		data: function() {
			return {
				activeName: 'first',
				flag: true,
				shortOrderList: [],
				// [{
				// 	"longremark": "string",
				// 	"longremark2": "string",
				// 	"longstate": "string",
				// 	"mealid": 0,
				// 	"shortcreatetime": "2019-10-13T13:05:22.457Z",
				// 	"shortdetail": "string",
				// 	"shortid": 0,
				// 	"shortprice": 0,
				// 	"u2id": 0,
				// 	"uid": 0
				// }],
				longOrderList: [],
				// [{
				// 	"longcreatetime": "2019-10-13T13:05:22.397Z",
				// 	"longdetail": "string",
				// 	"longedtime": "2019-10-13T13:05:22.398Z",
				// 	"longid": 0,
				// 	"longprice": 0,
				// 	"longremark": "string",
				// 	"longremark2": "string",
				// 	"longretime": "2019-10-13T13:05:22.398Z",
				// 	"longstate": "string",
				// 	"mealid": 0,
				// 	"u2id": 0,
				// 	"uid": 0
				// }],
				majorOrderList: [],
				Length: {
					longlength1: 0,
					longlength2: 0,
					longlength3: 0,
					longlengths: 0,
					shortlength1: 0,
					shortlength2: 0,
					shortlength3: 0,
					shortlengths: 0,
					majorlength1: 0,
					majorlength2: 0,
					majorlength3: 0,
					majorlengths: 0
				},
				assessList: {
					a1: 0,
					a2: 0,
					a3: 0,
					a4: 0,
					a5: 0
				},
				a: 0,
				Lengths: {
					math1: 0, //订单总体完成度
					math2: 0, //正在进行的订单
				},
				timer:'',
				select:'first'
			}
		},
		methods: {
			shortMethods() {
				let lengthss = 0
				let list=[]
				request({
					url: '/Order/shortOrderStages',
					method: 'get',
					params: {
						stage: "1"
					}
				}).then(res => {
					// console.log(res.data)

					lengthss = res.data.length
					res.data.forEach(e => {
						e.longstate = "未服务"
					})
					list = res.data
					// console.log(this.shortOrderList)
					return request({
						url: '/Order/shortOrderStages',
						method: 'get',
						params: {
							stage: "2"
						}
					})
				}).then(res => {
					lengthss = res.data.length + lengthss
					res.data.forEach(e => {
						e.longstate = "服务中"
						list.push(e)
					})
					return request({
						url: '/Order/shortOrderStages',
						method: 'get',
						params: {
							stage: "3"
						}
					})
				}).then(res => {
					lengthss = res.data.length + lengthss
					res.data.forEach(e => {
						e.longstate = "服务结束"
						list.push(e)
					})
					this.shortOrderList=list
					    if(this.$store.state.shortOrderNum<lengthss){
								this.$message({
								       message: '您有一条新的短期订单',
								       type: 'success'
								     });
							}
						 
					      
					this.$store.commit("updateShortOrderNum", lengthss)
				})
			},
			longMethods() {
				let lengthss = 0
				let list=[]
				request({
					url: '/Order/longOrderStages',
					method: 'get',
					params: {
						stage: "1"
					}
				}).then(res => {
					// console.log(res.data)

					lengthss = res.data.length
					res.data.forEach(e => {
						e.longstate = "未服务"
					})
					list = res.data
					// console.log(this.shortOrderList)
					return request({
						url: '/Order/longOrderStages',
						method: 'get',
						params: {
							stage: "2"
						}
					})
				}).then(res => {
					lengthss = res.data.length + lengthss
					res.data.forEach(e => {
						e.longstate = "服务中"
						list.push(e)
					})
					return request({
						url: '/Order/longOrderStages',
						method: 'get',
						params: {
							stage: "3"
						}
					})
				}).then(res => {
					lengthss = res.data.length + lengthss
					res.data.forEach(e => {
						e.longstate = "服务结束"
						list.push(e)
					})
					this.longOrderList=list
					 // console.log(this.longOrderList)
					    if(this.$store.state.longOrderNum<lengthss){
								this.$message({
								       message: '您有一条新的长期订单',
								       type: 'success'
								     });
							}
						 
					      
					this.$store.commit("updateLongOrderNum", lengthss)
				})
			},
			majorMethods() {
				let list=[]
				let lengthss = 0
				request({
					url: '/Order/majorOrderStages',
					method: 'get',
					params: {
						stage: "1"
					}
				}).then(res => {
					// console.log(res.data)

					lengthss = res.data.length
					res.data.forEach(e => {
						e.majorstate = "未服务"
					})
					list=res.data
					// this.majorOrderList = res.data
					// console.log(this.shortOrderList)
					return request({
						url: '/Order/majorOrderStages',
						method: 'get',
						params: {
							stage: "2"
						}
					})
				}).then(res => {
					lengthss = res.data.length + lengthss
					res.data.forEach(e => {
						e.majorstate = "服务中"
						list.push(e)
					})
					return request({
						url: '/Order/majorOrderStages',
						method: 'get',
						params: {
							stage: "3"
						}
					})
				}).then(res => {
					lengthss = res.data.length + lengthss
					res.data.forEach(e => {
						e.majorstate = "服务结束"
						list.push(e)
					})
					this.majorOrderList=list
					if(this.$store.state.majorOrderNum<lengthss){
								this.$message({
								       message: '您有一条新的专业订单',
								       type: 'success'
								     });
							}
						 
					// console.log(this.majorOrderList)
					this.$store.commit("updateMajorOrderNum", lengthss)
				})
			},
			handleClick(tab, event) {
				if (tab.name == "first") {
					// this.$options.methods.shortMethods();
					this.shortMethods();
					this.select="first"

				}
				if (tab.name == "second") {
					this.longMethods()
					this.select="second"
				}
				if (tab.name == "third") {
					this.majorMethods()
					this.select="third"
				}
				if (tab.name == "four") {
					this.select="four"
				}
				if (tab.name == "five") {
					
					request({
							url: '/Order/longOrderStages',
							method: 'get',
							params: {
								stage: "1"
							}
						}).then(res => {
							// console.log(res.data)
							this.Length.longlength1 = res.data.length;
							// console.log(this.longOrderList)
							return request({
								url: '/Order/longOrders',
								method: 'get',
							})
						}).then(res => {
							this.Length.longlengths = res.data.length;
							return request({
								url: '/Order/longOrderStages',
								method: 'get',
								params: {
									stage: "3"
								}
							})
						}).then(res => {
							this.Length.longlength3 = res.data.length;
							return request({
								url: '/Order/longOrderStages',
								method: 'get',
								params: {
									stage: "2"
								}
							})
						})
						.then(res => {
							this.Length.longlength2 = res.data.length;
							return request({
								url: '/Order/shortOrders',
								method: 'get',
							})
						}).then(res => {
							this.Length.shortlengths = res.data.length;
							return request({
								url: '/Order/shortOrderStages',
								method: 'get',
								params: {
									stage: "1"
								}
							})
						}).then(res => {
							this.Length.shortlength1 = res.data.length;
							return request({
								url: '/Order/shortOrderStages',
								method: 'get',
								params: {
									stage: "3"
								}
							})
						})
						.then(res => {
							this.Length.shortlength3 = res.data.length;
							return request({
								url: '/Order/shortOrderStages',
								method: 'get',
								params: {
									stage: "2"
								}
							})
						}).then(res => {
							this.Length.shortlength2 = res.data.length;
							return request({
								url: '/Order/majorOrders',
								method: 'get',
							})
						}).then(res => {
							this.Length.majorlengths = res.data.length;
							return request({
								url: '/Order/majorOrderStages',
								method: 'get',
								params: {
									stage: "1"
								}
							})
						}).then(res => {
							this.Length.majorlength1 = res.data.length;
							return request({
								url: '/Order/majorOrderStages',
								method: 'get',
								params: {
									stage: "3"
								}
							})
						})
						.then(res => {
							this.Length.majorlength3 = res.data.length;
							return request({
								url: '/Order/majorOrderStages',
								method: 'get',
								params: {
									stage: "2"
								}
							})
						}).then(res => {
							this.Length.majorlength2 = res.data.length;
							let qq3 = this.Length.longlength3 + this.Length.shortlength3 + this.Length.majorlength3 //已完成订单的数量
							let qq2 = qq3 + this.Length.longlength2 + this.Length.shortlength2 + this.Length.majorlength2
							let qq1 = qq2 + this.Length.longlength1 + this.Length.shortlength1 + this.Length.majorlength1
							this.Lengths.math1 = Math.round((qq3 / qq1) * 100)
							let qqq2 = this.Length.longlength2 + this.Length.shortlength2 + this.Length.majorlength2
							let qqq1 = this.Length.longlength1 + this.Length.shortlength1 + this.Length.majorlength1
							if(qqq2==0&&qqq1==0){
								this.Lengths.math2=0
							}else{
							this.Lengths.math2 = Math.round((qqq1 / (qqq1 + qqq2)) * 100)
							}
					
						})
					request({
						url: '/Order/datelist',
						method: 'get',
						params: {
							stage: "-1",
							day: 7
						}
					}).then(res => {
						this.$store.commit("updateDaylist", res.data.math.map(e => e.toString()))
					})
					request({
						url: '/Assess/AssessesAll',
						method: 'get'
					}).then(res => {

						this.a = res.data.length
						let aa = res.data.filter(e => e.assessleve == 2).length
						this.assessList.a2 = Math.round((aa / this.a) * 100)
						aa = res.data.filter(e => e.assessleve == 1).length
						this.assessList.a1 = Math.round((aa / this.a) * 100)
						aa = res.data.filter(e => e.assessleve == 3).length
						this.assessList.a3 = Math.round((aa / this.a) * 100)
						aa = res.data.filter(e => e.assessleve == 4).length
						this.assessList.a4 = Math.round((aa / this.a) * 100)
						aa = res.data.filter(e => e.assessleve == 5).length
						this.assessList.a5 = Math.round((aa / this.a) * 100)
						// console.log(this.assessList)
					})
					this.select="five"
				}
			}
		},
		components: {
			// mealInfo,
			shortOrderInfo,
			orderBrowse,
			longOrderInfo,		
			majorOrderInfo
			// orderComplaint
		},
		created() {
			this.shortMethods();
		},
		mounted() {
			this.timer = setInterval(()=>{
				if(this.select=="first"){
					this.shortMethods();
					// console.log("执行1")
				}
			  if (this.select == "second") {
			  	this.longMethods()
					// console.log("执行2")
			  }
			  if (this.select == "third") {
			  	this.majorMethods()
					// console.log("执行3")

			  }
			},3000);
		}
	}
</script>

<style>
</style>
